<?php
if (isset($_SESSION['admin']) && $_SESSION['admin'] == 1)
{

       if (isset($_GET['action']) && $_GET['action']=='accept' && isset($_GET['applicate']) &&
   is_numeric($_GET['applicate'])){
   		$query = "UPDATE `application` SET
						`status`=1
                WHERE `id`={$_GET['applicate']}";
		$sql = mysql_query($query) or die(mysql_error());
   }
   if (isset($_GET['action']) && $_GET['action']=='refuse' && isset($_GET['applicate']) &&
   is_numeric($_GET['applicate'])){
   		$query = "UPDATE `application` SET
						`status`=2
                WHERE `id`={$_GET['applicate']}";
		$sql = mysql_query($query) or die(mysql_error());
   }
 ?>
 <center><a href="index.php?section=admin&mode=application"><big>[Новые]</big></a>
 <a href="index.php?section=admin&mode=applicationold"><big>[Рассмотренные]</big></a></center>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr bgcolor="#000000">
  <td width="100%">
  <table border="0" width="100%">
  	<tr bgcolor="#222222">
	<td valign="bottom" colspan="2" >
	Игра
	</td>
	<td valign="bottom" colspan="2" >
	Команда
	</td>
	<td valign="bottom" colspan="2" >
	Капитан
	</td>
	<td valign="bottom" colspan="2" >
	Pin-код
	</td>
    <td valign="bottom" colspan="2" >
	Решение
	</td>
	</tr>
 <?php
 $query="SELECT
  team, title, login, application.status, application.team_id, application.id, application.pin
    FROM
  application, teams, game, players
    WHERE
  application.game_id = game.id AND application.team_id = teams.id AND teams.cap_id = players.id AND application.status != 0";
$sqlapplication=mysql_query($query) or die(mysql_error());

for ($i=1;$i<=mysql_num_rows($sqlapplication);$i++){
   $application=mysql_fetch_assoc($sqlapplication);
   if ($application['status']==1) {$status="Принята <a href=\"index.php?section=admin&mode=applicationold&action=refuse&applicate={$application['id']}\">[Отклонить]</a></td></tr>";}
   if ($application['status']==2) {$status="Отклонена </td></tr>";}
print "<tr bgcolor=\"#333333\">
        <td valign=\"bottom\" colspan=\"2\">{$application['team']}</td>
        <td valign=\"bottom\" colspan=\"2\">{$application['title']}</td>
        <td valign=\"bottom\" colspan=\"2\">{$application['login']}</td>
        <td valign=\"bottom\" colspan=\"2\">{$application['pin']}</td>
        <td valign=\"bottom\" colspan=\"2\">{$status}
        ";
}


//for (mysql_num_rows($sql)==1)
?>
	</table>
	</td>
	</tr>
	</table>

<?php

    }
else print ('Время вашей сессии истекло!');

?>